<?php

namespace app\circle\model;

class DeptModel extends BaseModel
{
    protected $name = 'circle_dept'; //定义用户表
    //开启自动写入时间戳
    protected $autoWriteTimestamp = false;
    // 定义自动完成的属性
    protected $auto = []; //新增修改
    protected $insert = []; //插入
    protected $update = []; //修改
    //类型自动转换
    protected $type = [];

    /*读取器*/
    public function getDeptPathTextAttr($value,$data){
        $deptIds = $data['dept_path'];
        $deptIds = explode(",",$deptIds);
        unset($deptIds[0]);
        $data = '';
        foreach ($deptIds as $k=>$v){
            $deptinfo = $this->where('dept_id',$v)->find();
            $data .= ",".$deptinfo['dept_name'];
        }
        $data = substr($data,1);
        return $data;
    }

    /*修改器*/
    /**
     * 获取树型部门
     */
    public function getTree(){
        $deptList = $this->order('dept_sort')->select()->toArray();
        $deptList = \org\util\TreeUtil::tree($deptList, 'dept_name', 'dept_id', 'dept_pid');
        return $deptList;
    }
}